package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 菜品分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO) {
        log.info("菜品分页查询,参数为为: {}", categoryPageQueryDTO);
        PageResult pageResult = categoryService.CategryQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 添加菜品
     * @param categoryDTO
     * @return
     */
    @PostMapping
    public Result addCategory(@RequestBody CategoryDTO categoryDTO) {
        log.info("添加菜品,参数为为: {}", categoryDTO);
        categoryService.insertCategory(categoryDTO);
        return Result.success();
    }

    /**
     * 修改菜品
     * @param categoryDTO
     * @return
     */
    @PutMapping
    public Result updateCategory(@RequestBody CategoryDTO categoryDTO) {
        log.info("修改菜品,参数为为: {}", categoryDTO);
        categoryService.updateCategory(categoryDTO);
        return Result.success();
    }

    /**
     * 删除菜品
     * @param id
     * @return
     */
    @DeleteMapping
    public Result deleteCategory(@RequestParam Integer id) {
        log.info("修改菜品,参数为为: {}", id);
        categoryService.deleteCategory(id);
        return Result.success();
    }

    @GetMapping
    public Result<Category> searchClassesCategory(String type) {
        log.info("查询菜品分类,参数为为: {}", type);
//        Category category = categoryService.classesSearch(type);
        return Result.success(null);
    }

    /**
     * 分类列表查询
     * @param type
     * @return
     */
    @GetMapping("/list")
    public Result<List<Category>> stopOrStartCategory(String type) {
        log.info("查询菜品分类,参数为: {}", type);
        List<Category> categories = categoryService.classesSearch(type);
        return Result.success(categories);
    }
    @PostMapping("/status/{status}")
    public Result stopOrStartCategory(@PathVariable Integer status,Long id) {
        log.info("起售或停售,参数为: {} {}", status,id);
        categoryService.statusCategory(status, id);
        return Result.success();
    }



}
